<%--
  Created by IntelliJ IDEA.
  User: 徐洲
  Date: 2023/12/17
  Time: 11:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.bean.Category" %>
<%@ page import="java.util.List" %>
<%@ page import="com.bean.Article" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("UTF-8");
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<jsp:useBean id="categoryDao" class="com.daoImpl.CategoryDAOImpl"></jsp:useBean>
<jsp:useBean id="articleDao" class="com.daoImpl.ArticleDAOImpl"></jsp:useBean>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>摆烂俱乐部</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css">
    <!-- Google fonts - Roboto -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,700">
    <!-- owl carousel-->
    <link rel="stylesheet" href="vendor/owl.carousel/assets/owl.carousel.css">
    <link rel="stylesheet" href="vendor/owl.carousel/assets/owl.theme.default.css">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="css/custom.css">
    <!-- Favicon-->
    <link rel="shortcut icon" href="favicon.png">
    <!-- Tweaks for older IEs--><!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
</head>
<body>

<%--  获取用户名--%>
<%String username = (String) session.getAttribute("username");%>
<!-- navbar-->
<header class="header mb-5">
    <!--
    *** 头部 ***
    _________________________________________________________
    -->
    <jsp:include page="common/login.jsp"></jsp:include>

    <jsp:include page="common/top2.jsp"></jsp:include>
    <!-- 搜索 -->
    <jsp:include page="common/search.jsp"></jsp:include>
</header>


<%
    List<Category> categoryList = categoryDao.getCategoryName();
    request.setAttribute("categoryList", categoryList);
    String article_id = "";
    if (request.getParameter("article_id") != null){
        article_id = request.getParameter("article_id");
        request.setAttribute("article_id",article_id);
        Article articleDetail = articleDao.getArticleById(article_id);
        request.setAttribute("articleDetail", articleDetail);
    }
%>
<div id="all">
    <div id="content">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <!-- breadcrumb-->
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="index.jsp">家</a></li>
                            <li aria-current="page" class="breadcrumb-item active">修改文章</li>
                        </ol>
                    </nav>
                </div>

                <form class="col-lg-12" style="display: flex;" method="post" action="./article?action=edit" enctype="multipart/form-data">
                    <div class="col-lg-6" style="flex: 1">
                        <div class="box">
                            <h1>新文章</h1>
                            <p class="lead">还不是我们的注册客户吗?</p>
                            <p>With registration with us jj's com, fantastic musical instruments and much more opens to you!
                                The whole process will not take you more than a minute!</p>
                            <p class="text-muted">If you have any questions, please feel free to contact us, our customer
                                service center is working for you 24/7.</p>
                            <hr>
                            <input name="userid" type="hidden" value="<%=session.getAttribute("userid")%>">
                            <input name="article_id" type="hidden" value="${article_id}">
                            <div class="form-group">
                                <label for="article_title">文章标题</label>
                                <input name="article_title" id="article_title" required type="text" value="${articleDetail.article_title}" class="form-control">
                            </div>
                            <div class="form-group">
                                <label for="category_id" class="col-form-label">文章分类</label>
                                <select name="category_id" id="category_id" class="form-control">
                                    <c:forEach items="${categoryList}" var="item">
                                        <option value="${item.category_id}" ${item.category_name eq articleDetail.category_name ? 'selected' : ''}>${item.category_name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="form-group text-center">
                                <input type="file" name="article_cover" value="${articleDetail.article_cover}" id="file" accept="image/png,image/jpeg" style="display:none;">
                                <button type="button" class="btn btn-primary" onclick="document.getElementById('file').click()"> 上传文章封面图片</button>
                                <span id="filename">${articleDetail.article_cover}</span>
                            </div>
                            <div class="form-group text-center">
                                <button type="submit" name="submit" class="btn btn-primary"><i
                                        class="fa fa-user-md"></i> 修改
                                </button>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-6" style="flex: 1">
                        <div class="box">
                            <h1>填写文章内容</h1>
                            <p class="lead">已经是我们的用户了?</p>
                            <hr>
                            <div class="form-group">
                                <textarea class="form-control custom-textarea" required rows="20" name="content">${articleDetail.content}</textarea>
                            </div>
                        </div>
                    </div>
                </form>

            </div>
        </div>
    </div>
</div>
<!--
    *** 版权 ***
    _________________________________________________________
    -->
<jsp:include page="common/copyright.jsp"></jsp:include>

<!-- *** COPYRIGHT END ***-->
<!-- JavaScript files-->
<script>
    document.getElementById('file').addEventListener('change', function() {
        const filename = this.value.split('\\').pop();
        document.getElementById('filename').textContent = filename;
    });
</script>
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="vendor/jquery.cookie/jquery.cookie.js"> </script>
<script src="vendor/owl.carousel/owl.carousel.min.js"></script>
<script src="vendor/owl.carousel2.thumbs/owl.carousel2.thumbs.js"></script>
<script src="js/front.js"></script>
</body>
</html>